define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'userallinfo/index',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: 'userallinfo/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'userId',
                sortName: 'userId',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'userId', title: __('UserId')},
                        {field: 'name', title: __('Name')},
                        {field: 'phone', title: __('Phone')},
                        {field: 'createTime', title: __('CreateTime'), formatter: Table.api.formatter.datetime},
                        {field: 'firsttender_time', title: __('Firsttender_time'), formatter: Table.api.formatter.datetime},
                        {field: 'firsttender_account', title: __('Firsttender_account'),operate:false},
                        {field: 'tender_total', title: __('Tender_total'),operate:false},
                        {field: 'tender_count', title: __('Tender_count'),operate:false},
                        {field: 'repay', title: __('repay'),operate:false},
                        {field: 'cashtotal', title: __('Cashtotal'),operate:false},
                        {field: 'cashcount', title: __('Cashcount'),operate:false},



                        //$list[$key]['cashtotal'] = $cashtotal['total'];
                        //$list[$key]['cashcount'] = Db::name('cash')->where(['userId'=>$val['userId']])->count();;
                        //$list[$key]['repay'] = $repaytotal['total'];
                        //$list[$key]['firsttender_time'] = $first_tender['createTime'];
                        //$list[$key]['tender_total'] = $tendertotal['total'];
                        //$list[$key]['tender_count'] = Db::name('borrow_tender')->where(['userId'=>$val['userId']])->count();
                        //$list[$key]['firsttender_account'] = $first_tender['account'];

                        {field: 'operate', title: __('Operate'), events: Controller.api.events.operate, formatter: function (value, row, index) {
                            var detail = '<a class="btn btn-xs btn-success btn-detail">查看</a> ';
                            return detail + Table.api.formatter.operate.call(this, value, row, index, table);
                        }}
                    ]
                ],
                search: false,
                //启用普通表单搜索
                commonSearch: true,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: false
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            events: {//绑定事件的方法

                operate: $.extend({
                    'click .btn-detail': function (e, value, row, index) {
                        e.stopPropagation();
                        Backend.api.open('userallinfo/detail/ids/' + row['userId'], __('Detail'));
                    }
                }, Table.api.events.operate)
            }
        }
    };
    return Controller;
});